Skip to content

fix(elasticsearch): drop dict-literal default from restart handler conditionals#140

Merged
Oddly merged 1 commit intomainfrom
fix/ansible-219-strict-conditionals
Apr 23, 2026
Merged

fix(elasticsearch): drop dict-literal default from restart handler conditionals#140
Oddly merged 1 commit intomainfrom
fix/ansible-219-strict-conditionals

Conversation

@Oddly
Copy link
Copy Markdown
Owner

@Oddly Oddly commented Apr 23, 2026

Closes #139.

Ansible 2.19 tightened conditional evaluation so expressions like default({'changed': false}) inside a when: clause now fail with Conditional expressions must be strings.. The restart handlers in #137 all used that pattern to guard against the freshstart facts being undefined. Swapped to an attribute-level default (.changed | default(false) | bool), which is semantically equivalent — both forms return false (don't block the restart) when the fact is undefined or when .changed is missing — and parses cleanly under both 2.18 and 2.19.

The elasticsearch_default scenario's side_effect.yml already exercises the Restart Elasticsearch handler end-to-end on a 2-node cluster, so the code path is covered. Note that CI still pins ansible-core<2.19 because of the unrelated role_path scoping change blocking that upgrade, so 2.19-strict mode is not yet directly exercised by CI — the fix is equivalent on 2.18.

Scope is intentionally narrow to what #139 calls out. Other default({}) usages (in until: clauses across tasks) use empty-dict literals, not key-value dicts, and haven't been reported as failing; leaving those alone until we can actually run 2.19 in CI.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of Elasticsearch restart handler conditions to ensure proper evaluation and execution during restart operations.

…nditionals

Ansible 2.19 tightened conditional evaluation and now rejects expressions
like `default({'changed': false})` inside a `when:` with "Conditional
expressions must be strings." Replace the dict-literal default with an
attribute-level default, which is semantically equivalent and parses under
both 2.18 and 2.19.

Closes #139
@Oddly Oddly added the ci:run Trigger gated pull request CI label Apr 23, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: de5b9087-bb94-4008-a645-693f0be91cc2

📥 Commits

Reviewing files that changed from the base of the PR and between 0e109da and 3552d98.

📒 Files selected for processing (1)
  • roles/elasticsearch/handlers/main.yml

📝 Walkthrough

Walkthrough

Updated conditional expressions in Elasticsearch handlers to resolve Ansible 2.19 strict conditionals compatibility. Replaced dict-literal defaults with attribute-level defaults across four handlers, changing from default({'changed': false})) to attribute-level default(false) pattern to meet Ansible 2.19 requirements.

Changes

Cohort / File(s) Summary
Elasticsearch Handler Conditionals
roles/elasticsearch/handlers/main.yml
Updated when conditions in 4 handlers ("Mark Elasticsearch restart requested", "Restart Elasticsearch directly", "Clear direct Elasticsearch restart request", "Restart Elasticsearch rolling") by replacing dict-literal defaults (default({'changed': false})) with attribute-level defaults (default(false)) for _elasticsearch_freshstart.changed and _elasticsearch_freshstart_security.changed evaluations to comply with Ansible 2.19 strict conditional requirements.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing dict-literal defaults from restart handler conditionals to fix Ansible 2.19 compatibility.
Linked Issues check ✅ Passed The PR fully addresses issue #139 by replacing dict-literal defaults with attribute-level defaults in all four affected handlers, maintaining semantic equivalence as required.
Out of Scope Changes check ✅ Passed All changes are narrowly scoped to fixing the conditional pattern in elasticsearch handlers as specified in issue #139; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ansible-219-strict-conditionals

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot removed the ci:run Trigger gated pull request CI label Apr 23, 2026
@Oddly Oddly merged commit 7e0f950 into main Apr 23, 2026
53 checks passed
@Oddly Oddly deleted the fix/ansible-219-strict-conditionals branch April 23, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ansible 2.19 strict conditionals reject dict-literal default() in elasticsearch handlers

1 participant